local Jewel = import(".Jewel")

local AuctionItem = class("AuctionItem")

local check = function(v,d)
	if v then
		return v
	else
		return d
	end
end

function AuctionItem:read(value)
	self.uuid 			= check(value.uuid, self.uuid)
	self.itemType 		= check(value.auctionId, self.itemType)
	self.itemId 		= check(value.itemId, self.itemId)
	self.itemNum 		= check(value.itemNum, self.itemNum)
	self.OnItemNum 		= check(value.OnItemNum, self.OnItemNum)
	self.avgPrice 		= check(value.avgPrice, self.avgPrice)
	self.competePrice 	= check(value.competePrice, self.competePrice)
	self.myCompetePrice = check(value.myCompetePrice, self.myCompetePrice)
	self.uid            = check(value.uid, self.uid)
	self.lv 			= check(value.lv, self.lv)
	self.quality 		= check(value.quality, self.quality)
	self.onSaleClock 	= check(value.onSaleClock, self.onSaleClock)
    if self.onSaleClock then
        if self.itemType and string.len(self.itemType)>0 and tonumber(string.sub(self.itemType,0,1))==7 then
            self.showTime=self.onSaleClock+tonumber(GD:getSystemPar("auctionCompeteShowTime",600))
        else
            self.showTime=self.onSaleClock
	    end
    	self.offSaleTime 	= self.onSaleClock+tonumber(GD:getSystemPar("auctionDalayTime",24)*60)
    	--self.offSaleTime 	= self.onSaleClock+300
    end
	self.cell 			= check(value.cell, self.cell)
    if value.jewel then
        local jewel = Jewel.new()
        jewel:read(value.jewel)
	    self.jewel= check(jewel, self.jewel)
    end
end


function AuctionItem:write(value)
	value.uuid 			= self.uuid
	value.auctionId     = self.itemType
	value.itemId 		= self.itemId
	value.itemNum 		= self.itemNum
	value.OnItemNum 	= self.OnItemNum
	value.avgPrice 		= self.avgPrice
	value.competePrice 	= self.competePrice
	value.myCompetePrice= self.myCompetePrice
	value.uid           = self.uid
	value.lv 			= self.lv
	value.quality 		= self.quality
	value.onSaleClock 	= self.onSaleClock
	value.cell 			= self.cell
end

function AuctionItem:ctor()
	self.uuid 			= ""
	self.itemType 		= 0
	self.itemId 		= 0
	self.itemNum 		= 0
	self.OnItemNum 		= 0
	self.avgPrice 		= 0
	self.competePrice 	= 0
	self.myCompetePrice = 0
	self.uid = 0
	self.lv 			= 0
	self.quality 		= 0
	self.onSaleClock 	= nil
	self.showTime 	    = nil
	self.offSaleTime 	= nil
	self.cell 			= nil
	self.jewel 			= nil
end

return AuctionItem
